package com.atwisdom.star.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;


/**
 * Swagger配置类.
 */
@Configuration   // 声明当前配置类
public class SwaggerConfig {
    @Value("${swagger.basePackage}")
    private String basePackage;       // basePackage指定扫描的包

    @Value("${swagger.title}")
    private String title;           // 自定义当前文档的标题

    @Value("${swagger.description}")
    private String description;         // 自定义当前文档的详细描述

    @Value("${swagger.version}")
    private String version;         // 自定义当前文档的版本

    //自定义作者的信息，包括作者名字、个人主页、邮箱等相关信息
    @Value("${swagger.name}")
    private String name;
    @Value("${swagger.url}")
    private String url;
    @Value("${swagger.email}")
    private String email;
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage(basePackage))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        Contact contact = new Contact(name,url,email);
        return new ApiInfoBuilder()
                .title(title)
                .description(description)
                .version(version)
                .contact(contact)
                .build();
    }
}